﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;

namespace Presentation
{
    public partial class WithdrawEnterOther : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn1_Click(object sender, EventArgs e)
        {
            txtAmount.Text += "1";
        }

        protected void btn2_Click(object sender, EventArgs e)
        {
            txtAmount.Text += "2";
        }

        protected void btn3_Click(object sender, EventArgs e)
        {
            txtAmount.Text += "3";
        }

        protected void btn4_Click(object sender, EventArgs e)
        {
            txtAmount.Text += "4";
        }

        protected void btn5_Click(object sender, EventArgs e)
        {
            txtAmount.Text += "5";
        }

        protected void btn6_Click(object sender, EventArgs e)
        {
            txtAmount.Text += "6";
        }

        protected void btn7_Click(object sender, EventArgs e)
        {
            txtAmount.Text += "7";
        }

        protected void btn8_Click(object sender, EventArgs e)
        {
            txtAmount.Text += "8";
        }

        protected void btn9_Click(object sender, EventArgs e)
        {
            txtAmount.Text += "9";
        }

        protected void btn0_Click(object sender, EventArgs e)
        {
            txtAmount.Text += "0";
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtAmount.Text = "";
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            int AccID = int.Parse(Session["AccountID"].ToString());
            string CardNo = Session["CardNo"].ToString();
            Decimal amount = Decimal.Parse(txtAmount.Text);
            CustomerBLL cus = new CustomerBLL();
            Decimal moneyATM = cus.GetMoney(1);
            Decimal blacance = cus.GetBalance(AccID);
            Decimal check = Math.Abs(amount % 50000);
            if ((amount >= 50000) && (check == 0) && (blacance > amount) && (moneyATM > amount))
            {
                cus.Withdraw(amount, AccID, CardNo);
                Response.Redirect("WithdrawPrintReceipt.aspx");
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "alert", "alert('Withdraw fail, because blacance account or monye in ATM not enough or not divisible by 50000!');", true);
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://localhost:2439/MainPage.aspx");
        }
    }
}